home *** CD-ROM | disk | FTP | other *** search
- Path: locutus.rchland.ibm.com!usenet
- From: pstaite@vnet.ibm.com
- Newsgroups: comp.lang.c++
- Subject: Re: Random numbers
- Date: 10 Jan 1996 21:36:25 GMT
- Organization: IBM OS/2 Device Driver Development Rochester, MN
- Message-ID: <4d1bgp$qn6@locutus.rchland.ibm.com>
- References: <4cul2d$gi@news.ran.es>
- Reply-To: pstaite@vnet.ibm.com
- NNTP-Posting-Host: warpone.rchland.ibm.com
- X-Newsreader: IBM NewsReader/2 v1.2
-
- In <4cul2d$gi@news.ran.es>, mper@ran.es writes:
- >How many "random" numbers can be created using the rand() function without repitition.
- >I am using this routine for a physics projects which simulates alpha scattering (Rutherford
- >Scattering), and I do about 1 million iterations through the main loop, creating 1 million random numbers.
- >Obviously, if its just repeating the numbers, the whole point of the simulation is gone.
-
- Can't say for sure, try this:
-
- #include<iostream.h>
- #include<limits.h>
-
- int main() {
- cout << RAND_MAX << endl;
- return 0; }
-
- And it'll tell you what the max return is from rand(). However, a
- really poor rand() may exhibit cyclic behavior with a much shorter
- period than RAND_MAX. That is, if RAND_MAX is 32767 (as I bet it is ;-)
- rand() may not be capable of generating all 32768 possible values,
- worse, it may have cycles. Try passing the output of rand() through an
- FFT some time, very interesting... :-)
-
- See Knuth's "Art of Computer Programming" Vol II or "Numerical Recipies
- in C" or some other decent algorithms book for a good pseudo random
- number generator.
-
-
- Phil Staite, team OS/2
- internet: pstaite@vnet.ibm.com internal: pstaite@rchland
-
-